package com.controller;

import com.entities.CommonResult;
import com.entities.Payment;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.shared.Application;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.service.FeignService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 04-26-19:30
 */
@RestController
@DefaultProperties(defaultFallback = "global_define")
public class FeignController {

    @Resource
    private FeignService feignService;


    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> openFeignTest01(@PathVariable("id") Long id) {
        return feignService.getById(id);
    }

    @PostMapping("/consumer/payment/insert")
    public CommonResult<Payment> openFeignTest(Payment payment) {
        return feignService.create(payment);
    }

    @GetMapping("consumer/payment/timeout/{id}")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
    })
    public String openFeignTest(@PathVariable("id") Integer id) {
        return feignService.timeoutTest(id);
    }

    public String global_define() {
        return  "OpenFeignHystrix全局降级处理，O(∩_∩)O哈哈~";
    }
}
